<template>
  <van-popup
    get-container="#app"
    :value="value"
    @input="$emit('input', $event)"
    @open="isReport = false"
  >
    <!-- 默认插槽 -->
    <van-cell-group v-if="!isReport">
      <van-cell @click="disLike" icon="closed-eye">不感兴趣</van-cell>
      <van-cell is-link @click="isReport = true">反馈垃圾内容</van-cell>
      <van-cell icon="info-o">拉黑作者</van-cell>
    </van-cell-group>
    <van-cell-group v-else>
      <van-cell icon="arrow-left" @click="isReport = false">返回</van-cell>
      <van-cell
        @click="report(item.value)"
        v-for="item in reports"
        :key="item.value"
        >{{ item.label }}</van-cell
      >
      <!-- <van-cell>色情</van-cell>
      <van-cell>暴力</van-cell>
      <van-cell>低俗</van-cell>
      <van-cell>不适</van-cell>
      <van-cell>错误</van-cell>
      <van-cell>其他</van-cell> -->
    </van-cell-group>
  </van-popup>
  <!-- <van-popup v-model="value">内容</van-popup> -->
</template>

<script>
import { dislikeByIdApi, reportByIdApi } from '../../../api/article'
import { reports } from '../../../api/constants'
export default {
  emits: ['input'],
  props: {
    // 外边v-model传值：接收必须叫value
    value: {
      type: Boolean,
      default: false
    },
    artId: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      // 是否显示上报垃圾内容
      isReport: false,
      reports
    }
  },
  methods: {
    async disLike () {
      try {
        await dislikeByIdApi(this.artId)
        this.$toast.success('操作成功！')
        this.$emit('del-dlike')
        this.$emit('input', false)
      } catch (error) {
        console.dir(error)
        this.$toast.fail('操作失败！')
        this.$emit('report-art')
      }
    },
    async report (type) {
      try {
        await reportByIdApi(this.artId, type)
        this.$toast.success('举报成功！')
        this.$emit('input', false)
        this.$emit('report-art')
      } catch (error) {
        console.dir(error)
        if (error.response.status === 409) {
          return this.$toast.fail('已经举报过了！')
        }
        this.$toast.fail('举报失败！')
      }
    }
  }
}
</script>

<style lang="less" scoped>
.van-popup {
  width: 80%;
  border-radius: 4px;
}
</style>
